import { observable, action } from 'mobx';
import http from '../common/http';
import paramInspect from '../common/paramInspect';

class AdvertisementStore {
  constructor(rootStore) {
    this.rootStore = rootStore
  }

  @observable advertisementParam = {
    "pageIndex": 1,
    "pageSize": 10,
    "delState": false
  };
  @observable advertisementList = [];
  @observable advertisementTotal = 0;
  @observable advertisementLoadSuccess = false;

  @action toGetAdvertisementList = () => {
    this.rootStore.globalStore.toShowLoding();
    http.get('/advertisement/list', paramInspect(this.advertisementParam))
    .then((response) => {
      this.rootStore.globalStore.toHideLoading();
      if (response.success) {
        this.advertisementLoadSuccess = true
        this.advertisementList = response.data.dataList;
        this.advertisementTotal = response.data.total;
      }
    })
  }

  @action toChangePageNumber = (pageNumber) => {
    this.advertisementParam.pageIndex = pageNumber;
    this.toGetAdvertisementList();
  }

  @action toChangePageSize = (pageSize) => {
    this.advertisementParam.pageIndex = 1;
    this.advertisementParam.pageSize = pageSize;
    this.toGetAdvertisementList();
  }

  @action filterParamSearch = (param) => {
    this.advertisementParam.advertisementTitle = param.title;
    this.advertisementParam.startTime = param.startTime;
    this.advertisementParam.endTime = param.endTime;
    this.advertisementParam.pageIndex = 1;
    this.advertisementParam.advertisementCategory = ""
    this.toGetAdvertisementList();
  }

  @action toChangeListStatus = (status) => {
    this.advertisementParam.pageIndex = 1;
    this.advertisementParam.pageSize = 10;
    this.advertisementParam.advertisementStatus = status;
    this.toGetAdvertisementList();
  }

  @action toChangeCategoryFilter = (item, id) => {
    this.advertisementParam.advertisementCategory = id;
    this.toGetAdvertisementList();
  }

  @observable categoryParam = {
    "delState": false,
    "pageIndex": 1,
    "pageSize": 50,
  }
  @observable adCategorySuccess = false
  @observable adCategoryList = []

  @action toGetAdsCategory = () => {
    this.rootStore.globalStore.toShowLoding();
    http.get('/news/category/page', this.categoryParam)
    .then((response) => {
      this.rootStore.globalStore.toHideLoading();
      if (response.success) {
        this.adCategorySuccess = true
        this.adCategoryList = response.data.dataList
      }
    })
  }

}


export default AdvertisementStore;
